package com.fymxy.question_bank_management.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fymxy.question_bank_management.pojo.Student;

import java.util.List;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

@Mapper
@Component
public interface StudentMapper {

    @Update("update student set student_name=#{name} where student_no=#{studentNo} ")
    int update(int studentNo, String name);

    int deleteByPrimaryKey(Integer studentNo);


    //插入teacher
    @Insert("insert into student (student_name,student_nickname,student_pwd,student_discipline) values " +
            "(#{studentName},#{studentNickname},#{studentPwd},#{studentDiscipline})")
    int insert(Student record);

    int insertSelective(Student record);


    //学生登录
    @Select("select student_no,student_nickname,student_name,student_pwd,student_discipline,student_grade from student where student_nickname = #{username} and student_pwd = #{password}")
    @Results(id = "studentMap",value = {
            @Result(column = "student_no",property = "studentNo",id = true),
            @Result(column = "student_name",property = "studentName"),
            @Result(column = "student_pwd",property = "studentPwd"),
            @Result(column = "student_nickname",property = "studentNickname"),
            @Result(column = "student_discipline",property = "studentDiscipline"),
            @Result(column = "student_grade",property = "studentGrade")
    })
    public Student studentLogin(String username, String password);

    @Select("select DISTINCT student.student_no,student.student_nickname,student.student_name,student.student_discipline" +
            "student.student_grade from student,student2course where student.student_no = student2course.student_no and course_no = #{courseNo}")
    public IPage<Student> selectStudentByCourse(Page page,Integer courseNo);
    Student selectByPrimaryKey(Integer studentNo);

    int updateByPrimaryKeySelective(Student record);

    int updateByPrimaryKey(Student record);
}